#include <stdio.h>
#include <stdlib.h>
#include <pic18f6722.h>

#define uint unsigned int
#define uchar unsigned char
#define uchar unsigned char
#define uint unsigned int

void PIC_Initialize()
{
 
}
//*********************************************************************
/* Set output or intput
 * 1 = input
 * 0 = output
 * author: Guichuan.He
 * date: 2016-9-22
*/
//**********************************************************************
void GPIO_Initialize()
{
//Set port E; 
    PORTE  = 0x00;        //Initialize PORT E by clearing output data latches
    LATE   = 0x00;        //Alternate method to clear output data latches
    TRISE  = 0x00;        //RE0: OUTPUT, 
                          //RE1: OUTPUT, 
                          //RE2: OUTPUT, MOTOR_RESET
                          //RE3: OUTPUT, MOTOR_SLEEP
                          //RE4: INPUT,  MOTOR_DECAY
                          //RE5: OUTPUT, MOTOR_IN2
                          //RE6: OUTPUT, MOTOR_IN1
                          //RE7: OUTPUT, MOTOR_I0
//*****************************************
//Set port F; 
    PORTF  = 0x00;        //Initialize PORT F by clearing output data latches
    LATF   = 0x00;        //Alternate method to clear output data latches
    ADCON1 = 0x0F;        //Set PORT A as digital I/O
    TRISF  = 0x00;        //RF0: OUTPUT, XXXXXX
                          //RF1: OUTPUT, XXXXXX
                          //RF2: OUTPUT, RED1
                          //RF3: OUTPUT, XXXXXX
                          //RF4: OUTPUT, XXXXXX
                          //RF5: OUTPUT, XXXXXX
                          //RF6: OUTPUT, XXXXXX
                          //RF7: OUTPUT, XXXXXX
//*****************************************
//Set port A; 
    PORTA  = 0x00;        //Initialize PORT A by clearing output data latches
    LATA   = 0x00;        //Alternate method to clear output data latches
    ADCON1 = 0x0F;        //Set PORT A as digital I/O
    TRISA  = 0x00;        //RF0: OUTPUT, SCL
                          //RF1: OUTPUT, SDA
                          //RF2: OUTPUT, XXXXXX
                          //RF3: OUTPUT, XXXXXX
                          //RF4: OUTPUT, XXXXXX
                          //RF5: OUTPUT, XXXXXX
                          //RF6: OUTPUT, XXXXXX
                          //RF7: OUTPUT, XXXXXX
//*****************************************
//Set port D; 
    PORTD  = 0x00;        //Initialize PORT D by clearing output data latches
    LATD   = 0x00;        //Alternate method to clear output data latches
    TRISD  = 0xC0;        //RD0: OUTPUT, MOTOR_I1
                          //RD1: OUTPUT, MOTOR_I2
                          //RD2: OUTPUT, MOTOR_I3
                          //RD3: OUTPUT, MOTO_I4
                          //RD4: OUTPUT, XXXXXX
                          //RD5: OUTPUT, XXXXXX
                          //RD6: INPUT,  KEY1
                          //RD7: INPUT,  KEY2
//*****************************************
//Set port C; 
    PORTC  = 0x00;        //Initialize PORT C by clearing output data latches
    LATC   = 0x00;        //Alternate method to clear output data latches
    TRISC  = 0x80;        //RC0: OUTPUT, XXXXXX
                          //RC1: OUTPUT, XXXXXX
                          //RC2: OUTPUT, GREEN
                          //RC3: OUTPUT, XXXXXX
                          //RC4: OUTPUT, XXXXXX
                          //RC5: OUTPUT, XXXXXX
                          //RC6: OUTPUT, XXXXXX
                          //RC7: OUTPUT, WORK_LED  
  //*****************************************
//Set port G; 
    PORTG  = 0x00;        //Initialize PORT G by clearing output data latches
    LATG   = 0x00;        //Alternate method to clear output data latches
    TRISG  = 0x20;        //RG0: OUTPUT, XXXXXX
                          //RG1: OUTPUT, XXXXXX
                          //RG2: OUTPUT, XXXXXX
                          //RG3: OUTPUT, XXXXXX
                          //RG4: OUTPUT, XXXXXX
                          //RC5: INPUT,  nMCLR, When selected as a port pin(MCLRE = 0), it functions as a digital input only
//*****************************************
//Set port B; 
    PORTB  = 0x00;        //Initialize PORT B by clearing output data latches
    LATB   = 0x00;        //Alternate method to clear output data latches
    TRISB  = 0x03;        //RB0: INPUT,  MOTOR_FAULT
                          //RB1: INPUT,  GAS_GAUGE_ALCC
                          //RB2: OUTPUT, XXXXXX
                          //RB3: OUTPUT, XXXXXX
                          //RB4: OUTPUT, XXXXXX
                          //RB5: OUTPUT, XXXXXX
                          //RB6: OUTPUT, XXXXXX 
                          //RB7: OUTPUT, XXXXXX 
}
